/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.edu.sistemas.ceiebt.action;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import pe.edu.sistemas.ceiebt.bean.Usuario;

/**
 *
 * @author Davis
 */
public class loginAction extends org.apache.struts.action.Action {
    private pe.edu.sistemas.ceiebt.form.UsuarioForm objL_formUsuario;
    /* forward name="success" path="" */
    private static final String SUCCESS = "success";
    
    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        objL_formUsuario = (pe.edu.sistemas.ceiebt.form.UsuarioForm)form;

        Usuario objL_usuario = new Usuario();
        objL_usuario.setUsuario(objL_formUsuario.getUsuario());
        objL_usuario.setClave(objL_formUsuario.getPwd());

        ActionForward retorno = new ActionForward();

        if(objL_usuario.getUsuario().equals("admin") && objL_usuario.getClave().equals("root")){
            //Redirecciono a la pagina mapeada en el Strutsconfig
            retorno = mapping.findForward("welcome");
        }else{
            ActionErrors errors = new ActionErrors();
            //Los tags error.* estan en el archivo ApplicationResource.properties
            errors.add("no_existe",new ActionMessage("errors.impedir"));
            retorno = mapping.getInputForward();
        }

        return retorno;
    }
}
